﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Young3.FMSearch.Core.Attributes;
using Young3.FMSearch.Core.Entities.GameVersions;
using Young3.FMSearch.Core.Managers;
using Young3.FMSearch.Core.Offsets;

namespace Young3.FMSearch.Core.Entities.InGame
{
    public class PlayerRelationContainer : BaseObject
    {
        private List<PlayerRelations> relations = null;

        public PlayerRelationContainer(int memoryAddress, IVersion version)
            : base(memoryAddress, version)
        {
        }

        public PlayerRelationContainer(int memoryAddress, ArraySegment<byte> originalBytes, IVersion version)
            : base(memoryAddress, originalBytes, version)
        {
        }

        [FMEntityAttribute(0x4)]
        public byte RelationsTotal { get; set; }

        [FMEntityAttribute(0x5)]
        public byte RelationsMax { get; set; }

        private void InitRelations()
        {
            relations = new List<PlayerRelations>();
            int mem = PropertyInvoker.Get<Int32>(0x0, OriginalBytes, MemoryAddress, DatabaseMode);
            for (int i = 0; i < RelationsTotal; i++)
                relations.Add(new PlayerRelations(mem + (i * 12), Version));
        }

        public List<PlayerRelations> Relations
        {
            get
            {
                if (relations == null)
                    InitRelations();

                return relations;
            }
        }
    }
}
